# coding: utf-8
from sqlalchemy import Column, INT
from sqlalchemy_dm import VARCHAR, DATE, DATETIME ,NUMBER
from sqlalchemy.ext.declarative import declarative_base

# 创建对象的基类
Base = declarative_base()

# 用户类
class CompanyPositionModel(Base):
    # 用户
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_GGXX'
    # 表结构
    ID = Column(INT, primary_key=True, autoincrement=True)
    NAME = Column(VARCHAR(256))
    GSMC = Column(VARCHAR(256))
    TYPE = Column(VARCHAR(256))
    POS = Column(VARCHAR(256))
    HCGID = Column(VARCHAR(256))
    PCH = Column(VARCHAR(200))
    NAME_ID = Column(NUMBER)
    ZGJE = Column(VARCHAR(256))
    ZGBL = Column(VARCHAR(256))
    IMPORT = Column(NUMBER)
    IS_CYDW = Column(NUMBER)

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID  =data['ID'],
            NAME=data['NAME'],
            GSMC=data['GSMC'],
            TYPE=int(data['TYPE']),
            POS= data['POS'],
            HCGID= data['HCGID'],
            PCH= data['PCH'],
            NAME_ID=data['NAME_ID'],
            ZGJE=data['ZGJE'],
            ZGBL=data['ZGBL'],
            IMPORT=data['IMPORT'],
            IS_CYDW=data['IS_CYDW']
        )

    def to_all_dict(self):
        return {
            'ID'  : self.ID,
            'NAME': self.NAME,
            'TYPE': int(self.TYPE),
            'GSMC': self.GSMC,
            'POS': self.POS,
            'HCGID': self.HCGID,
            'PCH': self.PCH,
            'NAME_ID': self.NAME_ID,
            'ZGJE': self.ZGJE,
            'ZGBL': self.ZGBL,
            'IMPORT': self.IMPORT,
            'IS_CYDW': self.IS_CYDW
        }

    def to_dict(self):
        return {
            'ID'  : self.ID,
            'NAME': self.NAME,
            'GSMC': self.GSMC,
            'TYPE': int(self.TYPE),
            'POS' : self.POS,
            'HCGID': self.HCGID,
            'PCH': self.PCH,
            'NAME_ID': self.NAME_ID,
            'ZGJE': self.ZGJE,
            'ZGBL': self.ZGBL,
            'IMPORT': self.IMPORT,
            'IS_CYDW': self.IS_CYDW
        }
